package com.jp.xml.asn1;

//Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 1/21/2006 1:46:44 PM
//Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
//Decompiler options: packimports(3) 
//Source File Name:   Base64.java


import com.ibm.util.Hex;

public class Base64X
{

 public Base64X()
 {
	 
 }

 public static String decodeBitString(String str, int len)
 {
     StringBuffer buf = new StringBuffer();
     byte bb[] = com.ibm.util.Base64.toByteArray(str);
     byte mm[] = {
         -128, 64, 32, 16, 8, 4, 2, 1
     };
     int i = 0;
     int j = 0;
     int k = 0;
     while(i < len) 
     {
         if(j >= 8)
         {
             j = 0;
             k++;
         }
         if((bb[k] & mm[j]) == 0)
             buf.append('0');
         else
             buf.append('1');
         i++;
         j++;
     }
     return buf.toString();
 }

 public static String decodeOctetString(String str)
 {
     return Hex.toString(com.ibm.util.Base64.toByteArray(str));
 }

 public static String encodeBitString(String str)
 {
     String str_ = "";
     int l = str.length() / 8;
     if(str.length() % 8 > 0)
         l++;
     if(l > 0)
     {
         byte mm[] = {
             -128, 64, 32, 16, 8, 4, 2, 1
         };
         byte bb[] = new byte[l];
         int i = 0;
         int j = 8;
         int k = -1;
         while(i < str.length()) 
         {
             if(j >= 8)
             {
                 j = 0;
                 k++;
                 bb[k] = 0;
             }
             if(str.charAt(i) == '1')
                 bb[k] |= mm[j];
             i++;
             j++;
         }
         str_ = com.ibm.util.Base64.toString(bb);
     }
     return str_;
 }

 public static String encodeOctetString(String str)
 {
     return com.ibm.util.Base64.toString(Hex.toByteArray(str));
 }
}
